package igor.mass;

import igor.mass.comm.CommunicationClient;
import igor.mass.model.AndroidRoom;
import igor.mass.model.AndroidSmarthouse;
import igor.mass.model.SmarthouseXMLDec;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;

public class SmarthouseActivity extends TabActivity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);

	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    
		SmarthouseXMLDec dec = new SmarthouseXMLDec();
		CommunicationClient cclient = new CommunicationClient();
		String xml = cclient.getStructure();
		
		AndroidSmarthouse s = dec.decodeXML(xml);

		//Log.e("###",cclient.getPage());
		//AndroidSmarthouse s = dec.decodeXML(AndroidSmarthouse.XML());
		
	    Intent intent;  // Reusable Intent for each tab	
	    
	    int i=0;
	    for (AndroidRoom room : s.rooms) {

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, RoomActivity.class);
	    intent.putExtra("name", room.name);
	    intent.putExtra("room", room);
	    //intent.putExtra("devices", room.devices.toArray());
	    
	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("tag:"+room.name).setIndicator(room.name,
	                      res.getDrawable(R.drawable.ic_tab_artists))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	   	 tabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 90; 
	    i++;
	    }
	    
	    intent = new Intent().setClass(this, HelpActivity.class);
	    spec = tabHost.newTabSpec("tag:"+"help").setIndicator("help",
	                      res.getDrawable(R.drawable.ic_tab_artists))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	   	 tabHost.getTabWidget().getChildAt(i).getLayoutParams().width = 90; 

	   	 tabHost.setBackgroundResource(R.color.background);
	 //   tabHost.setCurrentTab(0);
	    

	}

}
